<?php
    $User = Zend_Auth::getInstance()->getIdentity();
?>

<h1>Blog

    <?php if (isset($this->category)) : $url = $this->url(array('alias' => $this->category->alias), 'blogcategoryrss'); ?>
        : <?php echo $this->category->title ?>
    <?php elseif (isset($this->author)) : $url = $this->url(array('login' => $this->author->login), 'blogauthorrss'); ?>
        : <?php echo $this->author->login ?>
    <?php else: $url = $this->url(array('controller'=>'rss'))?>
    <?php endif; ?>
    <a href="<?php echo $url ?>" class="pull-right badge badge-warning span1 textcenter" style="margin-left: 24px"><i class="icon-fire icon-white"></i>&nbsp;RSS</a>

    <?php if ($User && $User->role != Users_Model_User::ROLE_GUEST) : ?>
            <a href="<?php echo $this->url(array(
                                    'module' => 'blog',
                                    'controller' => 'post',
                                    'action' => 'create'), 'default', true) ?>" title="<?php $this->_e('New Post')?>" class="btn btn-primary btn-large pull-right">
                <?php $this->_e('New Post')?>
            </a>
        <?php endif; ?>
</h1>

<hr />
<?php if ($this->paginator->count()): ?>
    <?php foreach($this->paginator as $row): $url = $this->url(array('alias'=> $row->alias), 'blogpost');?>
    <article>
        <h3>
            <a href="<?php echo $url?>"><?php echo $row->title?></a> //
            <a href="<?php echo $this->url(array('alias' => $row->categoryAlias), 'blogcategory')?>"><?php echo $row->categoryTitle?></a>
        </h3>
        <div class="content">
            <?php echo $row->teaser?>
        </div>
        <footer>
            <?php echo $this->__('Posted in')?> <?php echo $this->date($row->published)?>
            <?php echo $this->__('by')?>
            <a href="<?php echo $this->url(array('login' => $row->login), 'blogauthor') ?>"><?php echo $row->login?></a>

            <a href="<?php echo $url?>" class="pull-right"><?php echo $this->__('Comments')?> (<span><?php echo $this->commentsCounter($row->id, 'blog', $this->paginator->getCurrentItems()->toArray(), 'id') ?></span>)</a>
        </footer>
    </article>
    <?php endforeach;?>
<?php else:?>
    <h4><?php echo $this->__('No posts')?></h4>
<?php endif?>
<?php echo $this->paginationControl($this->paginator, 'Sliding', 'pagination.phtml'); ?>